import Vue from 'vue';
import Vuex from 'vuex';
import user from './modules/user'
import game from './modules/game'
import tips from './modules/tips'
import handlegame from './modules/handlegame'
import websock from './modules/websock'
import register from './modules/register'
import player from './modules/player'
import config from './modules/config'
import pay from './modules/pay'
import createPersistedState from 'vuex-persistedstate';
Vue.use(Vuex);

// const modulesFiles = require.context('./modules', true, /\.js$/)
// //动态转换model
// const modules = modulesFiles.keys().reduce((modules, modulePath) => {
//     // set './app.js' => 'app'
//     const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
//     const value = modulesFiles(modulePath)
//     modules[moduleName] = value.default
//     console.log('modules', modules);
//     return modules
// }, {})

const store = new Vuex.Store({
    modules: {
        game,
        tips,
        handlegame,
        websock,
        register,
        player,
        config,
        pay,
        user // 注册你的用户模块
        // 其他模块
    },
    plugins: [
        //注册模块并保存数据
        createPersistedState({
            storage: window.sessionStorage,
            paths: ["user","pay","config", "game", "handlegame", "tips", "websock", "register", "player"]
        })
    ],
});

export default store;
